<template>
  <el-dialog
    title="转正"
    :visible.sync="showDialog"
    :close-on-click-modal="issShow"
    :show-close="issShow"
    @closed="closeDialog"
  >
    <div class="header">
      <img
        v-if="positiveList.staffPhoto !== undefined"
        v-err="defaultAvatar"
        style="float:left"
        :src="positiveList.staffPhoto"
        alt=""
        class="img"
      >
      <img
        v-else
        v-err="defaultAvatar"
        style="float:left"
        src="positiveList.staffPhoto"
        alt=""
        class="img"
      >
      <p>
        {{ positiveList.username }}
      </p>
      <div>
        <span>手机<b> {{ positiveList.mobile }}</b></span>
        <span>部门<b>{{ positiveList.departmentName }}</b></span>
      </div>
      <div>
        <span>入职时间<b>{{
          positiveList.timeOfEntry | formatDate('yyyy-MM-dd')
        }}</b></span>
      </div>
    </div>
    <el-divider />
    <el-form
      ref="ruleForm"
      :model="ruleForm"
      :rules="rules"
      label-width="100px"
      class="demo-ruleForm"
    >
      <el-form-item label="转正时间" required>
        <el-col :span="11">
          <el-form-item prop="dateOfCorrection">
            <el-date-picker
              v-model="ruleForm.dateOfCorrection"
              type="date"
              placeholder="选择日期"
              style="width: 100%;"
            />
          </el-form-item>
        </el-col>
      </el-form-item>
      <el-form-item label="转正评价" prop="correctionEvaluation">
        <el-input v-model="ruleForm.correctionEvaluation" type="textarea" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="showDialog = false">取 消</el-button>
      <el-button type="primary" @click="confirm">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { addPositive } from '@/api/employee'
import defaultAvatar from '@/assets/common/headPortrait.png'
export default {
  name: 'BecomeDialog',
  components: {},
  data() {
    return {
      issShow: false,
      showDialog: false,
      positiveList: {},
      defaultAvatar,
      ruleForm: {},
      rules: {
        correctionEvaluation: [
          { required: true, message: '转正评价不能为空', trigger: 'blur' }
        ],
        dateOfCorrection: [
          {
            type: 'date',
            required: true,
            message: '请选择日期',
            trigger: 'change'
          }
        ]
      }
    }
  },
  methods: {
    // 确认的点击事件
    confirm() {
      this.$refs.ruleForm.validate(async valid => {
        if (valid) {
          await addPositive(this.positiveList.id, {
            correctionEvaluation: this.ruleForm.correctionEvaluation,
            dateOfCorrection: this.ruleForm.dateOfCorrection
          })
          this.$message.success('转正成功')
          this.$parent.getList()
          this.showDialog = false
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    // 关闭弹窗的回调事件
    closeDialog() {
      console.log(this.positiveList.staffPhoto)
      this.$refs.ruleForm.resetFields()
      this.ruleForm = {}
    }
  }
}
</script>

<style lang="scss">
.header {
  margin-top: 20px;
  margin-left: 15px;
  height: 130px;
  line-height: 26px;
  p {
    margin: 0;
    font-weight: 700;
  }
  span {
    padding-right: 15px;
    color: #999999;
    b {
      padding-left: 5px;
      color: #606266;
      font-weight: normal;
    }
  }
  img {
    width: 100px;
    margin-right: 20px;
    height: 100px;
    border-radius: 50%;
  }
}
.el-divider--horizontal {
  margin: 0 0 18px 0;
}
.el-textarea {
  width: 64%;
}
</style>
